using NUnit.Framework;

namespace Solver
{
	/// <summary>
	/// Find the last ten digits of 1^1 + 2^2 + ... + 1000^1000.
	/// </summary>
	public class Problem048 : SelfChecker, IProblem
	{
		public int Id
		{
			get { return 48; }
		}

		public string Solve()
		{
			return Solve(1000).ToString();
		}

		[Test]
		public override void Check()
		{
			Assert.AreEqual(405071317, Solve(10));
			Assert.AreEqual(9110846700, Solve(1000));
		}

		private static long Solve(int param)
		{
			const long mod = 10000000000;
			long s = 0;
			for (var n = 1; n <= param; n++)
			{
				long p = 1;
				for (var k = 1; k <= n; k++)
				{
					p *= n;
					p %= mod;
				}
				s += p;
				s %= mod;
			}
			return s;
		}
	}
}